/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.ec;

import it.polimi.registration.business.security.jsf.UserController;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Egzon
 */
@Entity
@Table(name = "Event")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Event.findAll", query = "SELECT e FROM Event e"),
    @NamedQuery(name = "Event.findByEventID", query = "SELECT e FROM Event e WHERE e.eventID = :eventID"),
    @NamedQuery(name = "Event.findByEventEndingTime", query = "SELECT e FROM Event e WHERE e.eventEndingTime = :eventEndingTime"),
    @NamedQuery(name = "Event.findByEventName", query = "SELECT e FROM Event e WHERE e.eventName = :eventName"),
    @NamedQuery(name = "Event.findByEventPrivacy", query = "SELECT e FROM Event e WHERE e.eventPrivacy = :eventPrivacy"),
    @NamedQuery(name = "Event.findByEventStartingTime", query = "SELECT e FROM Event e WHERE e.eventStartingTime = :eventStartingTime"),
    @NamedQuery(name = "Event.findByEventType", query = "SELECT e FROM Event e WHERE e.eventType = :eventType")})
public class Event implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "eventID")
    private Integer eventID;
    @Column(name = "eventEndingTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date eventEndingTime;
    @Size(max = 255)
    @Column(name = "eventName")
    private String eventName;
    @Column(name = "eventPrivacy")
    private Boolean eventPrivacy;
    @Column(name = "eventStartingTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date eventStartingTime;
    @Size(max = 255)
    @Column(name = "eventType")
    private String eventType;
    @JoinTable(name = "ParticipatesToEvent", joinColumns = {
        @JoinColumn(name = "eventID", referencedColumnName = "eventID")}, inverseJoinColumns = {
        @JoinColumn(name = "userID", referencedColumnName = "userID")})
    @ManyToMany
    private Collection<User> userCollection;
    @OneToMany(mappedBy = "eventID")
    private Collection<Invitation> invitationCollection;
    @JoinColumn(name = "createdBy", referencedColumnName = "userID")
    @ManyToOne
    private User createdBy;
    @JoinColumn(name = "eventLocation", referencedColumnName = "addressID")
    @ManyToOne
    public Address eventLocation;

    public Event() {
    }

    public Event(Integer eventID) {
        this.eventID = eventID;
    }

    public Integer getEventID() {
        return eventID;
    }

    public void setEventID(Integer eventID) {
        this.eventID = eventID;
    }

    public Date getEventEndingTime() {
        return eventEndingTime;
    }

    public void setEventEndingTime(Date eventEndingTime) {
        this.eventEndingTime = eventEndingTime;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public Boolean getEventPrivacy() {
        return eventPrivacy;
    }

    public void setEventPrivacy(Boolean eventPrivacy) {
        this.eventPrivacy = eventPrivacy;
    }

    public Date getEventStartingTime() {
        return eventStartingTime;
    }

    public void setEventStartingTime(Date eventStartingTime) {
        this.eventStartingTime = eventStartingTime;
    }

    public String getEventType() {
        return eventType;
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    @XmlTransient
    public Collection<User> getUserCollection() {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

    @XmlTransient
    public Collection<Invitation> getInvitationCollection() {
        return invitationCollection;
    }

    public void setInvitationCollection(Collection<Invitation> invitationCollection) {
        this.invitationCollection = invitationCollection;
    }

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public Address getEventLocation() {
        return eventLocation;
    }

    public void setEventLocation(Address eventLocation) {
        this.eventLocation = eventLocation;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (eventID != null ? eventID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.eventID == null && other.eventID != null) || (this.eventID != null && !this.eventID.equals(other.eventID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.registration.business.security.ec.Event[ eventID=" + eventID + " ]";
    }
    
    
}
